<template>
  <div class="classify">
    <div class="title">
      <span class="name">Explorar por categoria</span>
      <span class="more" @click="handleMore">Ver todas</span>
    </div>
    <!--  骨架屏-->
    <div class="skeleton" v-if="typeList.length===0">
      <div v-for="(item,index) in 3" :key="index">
        <van-skeleton avatar avatar-size="70px" :loading="true"></van-skeleton>
        <div class="skeleton-div"></div>
      </div>
    </div>
    <div class="list" v-else>
      <div class="item" @click="handleMore">
        <div style="width:80px;height:80px;display:flex;align-items: center;justify-content: center;">
          <img :src="domain + '/group1/default/20210224/14/35/4/favicon.png'" alt="" style="width:60px;height:60px"/>
        </div>
        <span>Todos os anúncios</span>
      </div>
      <div class="item" v-for="(item, index) in typeList" :key="index" @click="handleDetail(item)">
        <img :src="item.imgUrl" alt="" />
        <span>{{ item.showName }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import Api from "@/api";
import { getImgUrl } from "@/utils";
import { Domain } from "@/constants";
export default {
  name: "CuClassify",
  data() {
    return {
      typeList: [],
      domain: Domain,
    };
  },
  mounted() {
    this.loadTypeData();
  },
  methods: {
    loadTypeData() {
      Api.goodsTypeList().then((res) => {
        const result = res.map((item) => Object.assign(item, { imgUrl: getImgUrl(item.imgPath) }));
        this.typeList = result;
      });
    },
    handleDetail(item) {
      this.$router.push({
        path: "/result",
        query: {
          sectionName: item.showName,
          sectionId: item.id,
        },
      });
    },
    handleMore() {
      this.$router.push({
        path: "/result",
        query: {
          cateShow: 1,
        },
      });
    },
  },
};
</script>
<style lang="less" scoped>
.classify {
  background: #fff;
  padding: 10px;
  .title {
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #ededed;
    .name {
      font-size: 20px;
      font-weight: 500;
      color: #333;
    }
    .more {
      color: #999;
      font-size: 14px;
    }
  }
  .list {
    display: flex;
    flex-wrap: nowrap;
    width: 100%;
    overflow: auto;
    padding: 15px 0;
    box-sizing: border-box;
    .item {
      width: 100px;
      margin-right: 10px;
      display: flex;
      flex-direction: column;
      align-items: center;
      img {
        width: 80px;
        height: 80px;
        border-radius: 100%;
      }
      span {
        color: #666;
        font-size: 14px;
        margin-top: 10px;
        padding: 0 5px;
      }
    }
  }
}
.skeleton{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  .skeleton-div{
    width: 90px;
    height: 20px;
    border-radius: 10px;
    background-color: #f2f3f5;
    margin-top: 10px;
    margin-left: 5px;
  }
}

</style>
